////
//// Source code recreated from a .class file by IntelliJ IDEA
//// (powered by FernFlower decompiler)
////
//
//package org.postgresql.core;
//
//import java.io.IOException;
//import java.sql.SQLException;
//import java.sql.SQLWarning;
//import java.util.ArrayList;
//import java.util.Properties;
//import org.postgresql.GlobalConnectionTracker;
//import org.postgresql.PGNotification;
//import org.postgresql.PGProperty;
//import org.postgresql.jdbc.AutoSave;
//import org.postgresql.jdbc.DbCompatibility;
//import org.postgresql.jdbc.PreferQueryMode;
//import org.postgresql.log.Log;
//import org.postgresql.log.Logger;
//import org.postgresql.util.HostSpec;
//import org.postgresql.util.LruCache;
//import org.postgresql.util.PSQLException;
//import org.postgresql.util.PSQLState;
//import org.postgresql.util.ServerErrorMessage;
//
//public abstract class QueryExecutorBase implements QueryExecutor {
//    private static Log LOGGER = Logger.getLogger(QueryExecutorBase.class.getName());
//    protected final PGStream pgStream;
//    private final String user;
//    private final String database;
//    private final int cancelSignalTimeout;
//    private int cancelPid;
//    private int cancelKey;
//    private boolean closed = false;
//    private String serverVersion;
//    private int serverVersionNum = 0;
//    private TransactionState transactionState;
//    private final boolean reWriteBatchedInserts;
//    private final boolean columnSanitiserDisabled;
//    private final PreferQueryMode preferQueryMode;
//    private AutoSave autoSave;
//    private boolean flushCacheOnDeallocate = true;
//    private Properties props;
//    private boolean standardConformingStrings = false;
//    private boolean valid = true;
//    private SQLWarning warnings;
//    private final ArrayList<PGNotification> notifications = new ArrayList();
//    private final LruCache<Object, CachedQuery> statementCache;
//    private final CachedQueryCreateAction cachedQueryCreateAction;
//
//    protected QueryExecutorBase(PGStream pgStream, String user, String database, int cancelSignalTimeout, Properties info) throws SQLException {
//        this.pgStream = pgStream;
//        this.user = user;
//        this.database = database;
//        this.cancelSignalTimeout = cancelSignalTimeout;
//        this.reWriteBatchedInserts = PGProperty.REWRITE_BATCHED_INSERTS.getBoolean(info);
//        this.columnSanitiserDisabled = PGProperty.DISABLE_COLUMN_SANITISER.getBoolean(info) || DbCompatibility.ORACLE == DbCompatibility.of(PGProperty.DB_COMPATIBILITY.get(info));
//        String preferMode = PGProperty.PREFER_QUERY_MODE.get(info);
//        this.preferQueryMode = PreferQueryMode.of(preferMode);
//        this.autoSave = AutoSave.of(PGProperty.AUTOSAVE.get(info));
//        this.cachedQueryCreateAction = new CachedQueryCreateAction(this);
//        this.props = info;
//        this.statementCache = new LruCache(Math.max(0, PGProperty.PREPARED_STATEMENT_CACHE_QUERIES.getInt(info)), (long)Math.max(0, PGProperty.PREPARED_STATEMENT_CACHE_SIZE_MIB.getInt(info) * 1024 * 1024), false, this.cachedQueryCreateAction, new LruCache.EvictAction<CachedQuery>() {
//            public void evict(CachedQuery cachedQuery) throws SQLException {
//                cachedQuery.query.close();
//            }
//        });
//    }
//
//    protected abstract void sendCloseMessage() throws IOException;
//
//    public void setNetworkTimeout(int milliseconds) throws IOException {
//        this.pgStream.setNetworkTimeout(milliseconds);
//    }
//
//    public int getNetworkTimeout() throws IOException {
//        return this.pgStream.getNetworkTimeout();
//    }
//
//    public HostSpec getHostSpec() {
//        return this.pgStream.getHostSpec();
//    }
//
//    public String getUser() {
//        return this.user;
//    }
//
//    public String getDatabase() {
//        return this.database;
//    }
//
//    public void setBackendKeyData(int cancelPid, int cancelKey) {
//        this.cancelPid = cancelPid;
//        this.cancelKey = cancelKey;
//    }
//
//    public int getBackendPID() {
//        return this.cancelPid;
//    }
//
//    public void abort() {
//        try {
//            this.pgStream.getSocket().close();
//        } catch (IOException e) {
//            LOGGER.trace("Catch IOException on close:", e);
//        }
//
//        this.closed = true;
//    }
//
//    public void close() {
//        if (!this.closed) {
//            try {
//                LOGGER.trace(" FE=> Terminate");
//                this.sendCloseMessage();
//                this.pgStream.flush();
//                this.pgStream.close();
//                GlobalConnectionTracker.releaseConnectionReference(this, this.props);
//            } catch (IOException ioe) {
//                LOGGER.trace("Discarding IOException on close:", ioe);
//            }
//
//            this.closed = true;
//        }
//    }
//
//    public boolean isClosed() {
//        return !this.valid || this.closed;
//    }
//
//    public void setAvailability(boolean availability) {
//        this.valid = availability;
//    }
//
//    public void sendQueryCancel() throws SQLException {
//        if (this.cancelPid > 0) {
//            PGStream cancelStream = null;
//
//            try {
//                if (LOGGER.isTraceEnabled()) {
//                    LOGGER.trace(" FE=> CancelRequest(pid=" + this.cancelPid + ",ckey=" + this.cancelKey + ")");
//                }
//
//                cancelStream = new PGStream(this.pgStream.getSocketFactory(), this.pgStream.getHostSpec(), this.cancelSignalTimeout);
//                if (this.cancelSignalTimeout > 0) {
//                    cancelStream.getSocket().setSoTimeout(this.cancelSignalTimeout);
//                }
//
//                cancelStream.sendInteger4(16);
//                cancelStream.sendInteger2(1234);
//                cancelStream.sendInteger2(5678);
//                cancelStream.sendInteger4(this.cancelPid);
//                cancelStream.sendInteger4(this.cancelKey);
//                cancelStream.flush();
//                cancelStream.receiveEOF();
//            } catch (IOException e) {
//                LOGGER.trace("Ignoring exception on cancel request:", e);
//                throw new SQLException("Cancel request on this connection failed");
//            } finally {
//                if (cancelStream != null) {
//                    try {
//                        cancelStream.close();
//                    } catch (IOException e) {
//                        LOGGER.trace("Catch IOException on close:", e);
//                    }
//                }
//
//            }
//
//        }
//    }
//
//    public synchronized void addWarning(SQLWarning newWarning) {
//        if (this.warnings == null) {
//            this.warnings = newWarning;
//        } else {
//            this.warnings.setNextWarning(newWarning);
//        }
//
//    }
//
//    public synchronized void addNotification(PGNotification notification) {
//        this.notifications.add(notification);
//    }
//
//    public synchronized PGNotification[] getNotifications() throws SQLException {
//        PGNotification[] array = (PGNotification[])this.notifications.toArray(new PGNotification[this.notifications.size()]);
//        this.notifications.clear();
//        return array;
//    }
//
//    public synchronized SQLWarning getWarnings() {
//        SQLWarning chain = this.warnings;
//        this.warnings = null;
//        return chain;
//    }
//
//    public String getServerVersion() {
//        return this.serverVersion;
//    }
//
//    public int getServerVersionNum() {
//        return this.serverVersionNum != 0 ? this.serverVersionNum : (this.serverVersionNum = Utils.parseServerVersionStr(this.serverVersion));
//    }
//
//    public void setServerVersion(String serverVersion) {
//        this.serverVersion = serverVersion;
//    }
//
//    public void setServerVersionNum(int serverVersionNum) {
//        this.serverVersionNum = serverVersionNum;
//    }
//
//    public synchronized void setTransactionState(TransactionState state) {
//        this.transactionState = state;
//    }
//
//    public synchronized void setStandardConformingStrings(boolean value) {
//        this.standardConformingStrings = value;
//    }
//
//    public synchronized boolean getStandardConformingStrings() {
//        return this.standardConformingStrings;
//    }
//
//    public synchronized TransactionState getTransactionState() {
//        return this.transactionState;
//    }
//
//    public void setEncoding(Encoding encoding) throws IOException {
//        this.pgStream.setEncoding(encoding);
//    }
//
//    public Encoding getEncoding() {
//        return this.pgStream.getEncoding();
//    }
//
//    public boolean isReWriteBatchedInsertsEnabled() {
//        return this.reWriteBatchedInserts;
//    }
//
//    public final CachedQuery borrowQuery(String sql) throws SQLException {
//        return (CachedQuery)this.statementCache.borrow(sql);
//    }
//
//    public final CachedQuery borrowCallableQuery(String sql) throws SQLException {
//        return (CachedQuery)this.statementCache.borrow(new CallableQueryKey(sql));
//    }
//
//    public final CachedQuery borrowReturningQuery(String sql, String[] columnNames) throws SQLException {
//        return (CachedQuery)this.statementCache.borrow(new QueryWithReturningColumnsKey(sql, true, true, columnNames));
//    }
//
//    public CachedQuery borrowQueryByKey(Object key) throws SQLException {
//        return (CachedQuery)this.statementCache.borrow(key);
//    }
//
//    public void releaseQuery(CachedQuery cachedQuery) {
//        this.statementCache.put(cachedQuery.key, cachedQuery);
//    }
//
//    public final Object createQueryKey(String sql, boolean escapeProcessing, boolean isParameterized, String... columnNames) {
//        Object key;
//        if (columnNames != null && columnNames.length == 0) {
//            if (isParameterized) {
//                key = sql;
//            } else {
//                key = new BaseQueryKey(sql, false, escapeProcessing);
//            }
//        } else {
//            key = new QueryWithReturningColumnsKey(sql, isParameterized, escapeProcessing, columnNames);
//        }
//
//        return key;
//    }
//
//    public CachedQuery createQueryByKey(Object key) throws SQLException {
//        return this.cachedQueryCreateAction.create(key);
//    }
//
//    public final CachedQuery createQuery(String sql, boolean escapeProcessing, boolean isParameterized, String... columnNames) throws SQLException {
//        Object key = this.createQueryKey(sql, escapeProcessing, isParameterized, columnNames);
//        return this.createQueryByKey(key);
//    }
//
//    public boolean isColumnSanitiserDisabled() {
//        return this.columnSanitiserDisabled;
//    }
//
//    public PreferQueryMode getPreferQueryMode() {
//        return this.preferQueryMode;
//    }
//
//    public AutoSave getAutoSave() {
//        return this.autoSave;
//    }
//
//    public void setAutoSave(AutoSave autoSave) {
//        this.autoSave = autoSave;
//    }
//
//    protected boolean willHealViaReparse(SQLException e) {
//        if (PSQLState.INVALID_SQL_STATEMENT_NAME.getState().equals(e.getSQLState())) {
//            return true;
//        } else if (PSQLState.INVALID_CACHE_PLAN.getState().equals(e.getSQLState())) {
//            return true;
//        } else if (!PSQLState.NOT_IMPLEMENTED.getState().equals(e.getSQLState())) {
//            return false;
//        } else if (!(e instanceof PSQLException)) {
//            return false;
//        } else {
//            PSQLException pe = (PSQLException)e;
//            ServerErrorMessage serverErrorMessage = pe.getServerErrorMessage();
//            if (serverErrorMessage == null) {
//                return false;
//            } else {
//                String routine = pe.getServerErrorMessage().getRoutine();
//                return "RevalidateCachedQuery".equals(routine) || "RevalidateCachedPlan".equals(routine);
//            }
//        }
//    }
//
//    public boolean willHealOnRetry(SQLException e) {
//        return this.autoSave == AutoSave.NEVER && this.getTransactionState() == TransactionState.FAILED ? false : this.willHealViaReparse(e);
//    }
//
//    public boolean isFlushCacheOnDeallocate() {
//        return this.flushCacheOnDeallocate;
//    }
//
//    public void setFlushCacheOnDeallocate(boolean flushCacheOnDeallocate) {
//        this.flushCacheOnDeallocate = flushCacheOnDeallocate;
//    }
//
//    protected boolean hasNotifications() {
//        return this.notifications.size() > 0;
//    }
//}
